package com.mmlc.meimei.lichengkongjian.home;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.androidnetframe.responsejavabean.RequestError;
import com.mmlc.inter.InterActivity;
import com.mmlc.inter.ViewPagerFragmentAdapter;
import com.mmlc.meimei.lichengkongjian.R;
import com.mmlc.meimei.lichengkongjian.classify.WebFragmentOther;
import com.mmlc.network.filter.FashionTitleListRequestFilter;
import com.mmlc.network.responsebean.FashionTitleListResponseBean;
import com.mmlc.widget.Indicator;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * description: 潮流资讯
 * by king
 * Created at 2016/8/26 13:08
 */
public class FashionInfoActivity extends InterActivity  {


    @InjectView(R.id.indicator_v)
    Indicator mIndicator;
    @InjectView(R.id.vp_fashion)
    ViewPager vp_fashion;


    ArrayList<Fragment> fragments;

    @Override
    protected int initContentView() {
        return R.layout.activity_fashion_info;
    }


    @Override
    protected void initView() {
        ButterKnife.inject(this);
        fragments = new ArrayList<>();
        initTitleData();

    }


    @OnClick(R.id.iv_back)
    public void onClick(View v) {
        finish();
    }


    int i = 0;
    Fragment fragment;
    private void displayViewPager(FashionTitleListResponseBean result) {

        List<String> titles = new ArrayList<>();
        for (FashionTitleListResponseBean.DataBean item : result.getData()) {
            titles.add(item.getName());
            Bundle bundle = new Bundle();
            bundle.putString("title", item.getName());
            bundle.putString("id", item.getId());
            if(i==0){//最美拍摄
//                fragment=new ZuiMeiPaiSheFragment();
                fragment=new WebFragmentOther();
                bundle.putString("url",item.getLink());
            }
            if(i == 1) {
                fragment = new RecommendFragment();
            }
            if(i == 2) {
                fragment = new InformationFragment();
            }
            fragment.setArguments(bundle);
            fragments.add(fragment);
            i++;
        }
        mIndicator.setTitles(titles);
        if (titles.size()>0)
        mIndicator.setVisibility(View.VISIBLE);
        vp_fashion.setAdapter(new ViewPagerFragmentAdapter(getSupportFragmentManager(), fragments));
        mIndicator.setmViewPager(vp_fashion, 0);

    }


    private void initTitleData() {
        FashionTitleListRequestFilter filter = new FashionTitleListRequestFilter(this);
        filter.sendRequest(new FashionTitleListRequestFilter.AccessResultFromFilter<FashionTitleListResponseBean>() {

            @Override
            public void onSuccess(FashionTitleListResponseBean result) {
                displayViewPager(result);
            }

            @Override
            public void onFailed(View errorLayout, RequestError serverError, int failedType) {

            }
        });
    }


}
